from django.shortcuts import render
from rest_framework.response import Response
from rest_framework.views import APIView

from cart.models import Cart
from cart.ser import CartSer, CartListSer
from login.models import User
from utils.authoriaztion import MyAuthentication


# Create your views here.
class CartSelect(APIView):
    authentication_classes = [MyAuthentication]

    def get(self,request):
        user = request.query_params.get('user',None)
        if not user:
            return Response({'msg':'参数不全'})
        cart = Cart.objects.filter(user=user,is_select=True)
        ser = CartListSer(cart,many=True)
        return Response({'msg':'ok','data':ser.data})
class MyCoupon(APIView):
    authentication_classes = [MyAuthentication]
    def get(self,request):
        user = request.query_params.get('user',None)
        if not user:
            return Response({'msg':'参数不全'})
        info = User.objects.filter(id=user).first()
        data = {'score':info.score,'coupon':[],"tomoney":10}
        return Response({'msg':'ok','data':data})